package com.ewanghuiju.app.ui.pintuan.activity;

import android.annotation.SuppressLint;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.base.BaseActivity;
import com.ewanghuiju.app.base.contract.pintuan.PintuanOrderDetailsContract;
import com.ewanghuiju.app.component.ImageLoader;
import com.ewanghuiju.app.component.RxBus;
import com.ewanghuiju.app.model.bean.response.PintuanOrderDetailsResponBean;
import com.ewanghuiju.app.model.bean.response.ShareResponBean;
import com.ewanghuiju.app.model.event.SendEvent;
import com.ewanghuiju.app.presenter.pintuan.PintuanOrderDetailsPresenter;
import com.ewanghuiju.app.ui.my.activity.WalletCenterActivity;
import com.ewanghuiju.app.ui.web.MyWebviewActivity;
import com.ewanghuiju.app.util.ClipboardUtils;
import com.ewanghuiju.app.util.LoadingDialogUtils;
import com.ewanghuiju.app.util.PermissionUtil;
import com.ewanghuiju.app.util.StartActivityUtil;
import com.ewanghuiju.app.util.StringUtil;
import com.ewanghuiju.app.util.TimeUtils;
import com.ewanghuiju.app.util.ToastUtil;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.ewanghuiju.app.util.thread.LoadImageDataThread;
import com.ewanghuiju.app.widget.popupwindow.CustomBasePopup;
import com.ewanghuiju.app.widget.popupwindow.ShareShopPopup;
import com.gyf.immersionbar.ImmersionBar;
import com.luck.picture.lib.PictureMediaScannerConnection;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.tools.SdkVersionUtils;
import com.luck.picture.lib.tools.ToastUtils;
import com.makeramen.roundedimageview.RoundedImageView;
import com.muddzdev.styleabletoast.StyleableToast;

import java.io.File;

import androidx.core.content.ContextCompat;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 拼团订单详情
 * @time 2020/2/19
 */
public class PintuanOrderDetailsActivity extends BaseActivity<PintuanOrderDetailsPresenter> implements PintuanOrderDetailsContract.View {
    @BindView(R.id.iv_position)
    ImageView ivPosition;
    @BindView(R.id.tv_order_name)
    TextView tvOrderName;
    @BindView(R.id.tv_order_number)
    TextView tvOrderNumber;
    //商品图片
    @BindView(R.id.rv_shop)
    RoundedImageView rvShop;
    //订单商品标题
    @BindView(R.id.tv_order_title)
    TextView tvOrderTitle;
    //规格
    @BindView(R.id.tv_order_guige)
    TextView tvOrderGuige;
    @BindView(R.id.tv_invite_friend)
    TextView tvInviteFriend;
    @BindView(R.id.tv_kefu)
    TextView tvKefu;
    //标题
//    @BindView(R.id.tv_title)
//    TextView tvTitle;
    //倒计时信息
    @BindView(R.id.tv_success_countdown)
    TextView tvSuccessCountdown;
    //地址信息
    @BindView(R.id.tv_address_details)
    TextView tvAddressDetails;
    //价格
    @BindView(R.id.tv_spe_price)
    TextView tvSpePrice;
    //商品价格
    @BindView(R.id.tv_shop_price)
    TextView tvShopPrice;
    //运费
    @BindView(R.id.tv_yunfei)
    TextView tvYunfei;
    //实付价格
    @BindView(R.id.tv_true_price)
    TextView tvTruePrice;
    @BindView(R.id.tv_order_no)
    TextView tvOrderNo;
    @BindView(R.id.layout_fh_time)
    LinearLayout layoutFhTime;
    @BindView(R.id.tv_create_time)
    TextView tvCreateTime;
    @BindView(R.id.tv_pay_time)
    TextView tvPayTime;
    @BindView(R.id.iv_shop_status)
    ImageView ivShopStatus;
    @BindView(R.id.tv_message)
    TextView tvMessage;
    @BindView(R.id.tv_status_text)
    TextView tvStatusText;
    @BindView(R.id.tv_pintuan_status)
    TextView tvPintuanStatus;
    @BindView(R.id.layout_kd)
    LinearLayout layoutKd;
    @BindView(R.id.tv_kd_name)
    TextView tvKdName;
    @BindView(R.id.tv_kd_no)
    TextView tvKdNo;
    @BindView(R.id.tv_kd_fhtime)
    TextView tvKdFhtime;
    @BindView(R.id.tv_get_water_no)
    TextView tvGetWaterNo;
    @BindView(R.id.layout_get_water_no)
    LinearLayout layoutGetWaterNo;
    @BindView(R.id.tv_get_fhd)
    TextView tvGetFhd;
    @BindView(R.id.layout_get_fhd)
    LinearLayout layoutGetFhd;
    @BindView(R.id.tv_get_jssy)
    TextView tvGetJssy;
    @BindView(R.id.layout_get_jssy)
    LinearLayout layoutGetJssy;
    //查看物流
    @BindView(R.id.tv_look_wuliu)
    TextView tvLookWuliu;
    //删除订单
    @BindView(R.id.tv_look_wallet)
    TextView tvLookWallet;
    //确认收货
    @BindView(R.id.tv_sure_sh)
    TextView tvSureSh;
    //立即评价
    @BindView(R.id.tv_ljpj)
    TextView tvLjpj;
    //支付方式
    @BindView(R.id.tv_pay_type)
    TextView tvPayType;
    @BindView(R.id.tv_order_remarks)
    TextView tvOrderRemarks;
    @BindView(R.id.layout_order_remarks)
    RelativeLayout layoutOrderRemarks;
    @BindView(R.id.layout_order_remarks_line)
    LinearLayout layoutOrderRemarksLine;

    private String orderId;
    private int from;

    private CountDownTimer countDownTimer;

    private PintuanOrderDetailsResponBean pintuanOrderDetailsResponBean;

    @Override
    protected int getLayout() {
        return R.layout.activity_pintuan_order_details;
    }

    @Override
    protected void initEventAndData() {
        from = getIntent().getIntExtra(Constants.PINTUANORDER_FROM, Constants.PINTUANORDER_FROM_CREATE_ORDER);
        orderId = getIntent().getStringExtra(Constants.PINTUANORDER_NO);
        if (TextUtils.isEmpty(orderId)) {
            StyleableToast.makeText(mContext, "未获取到订单信息", Toast.LENGTH_SHORT, R.style.mytoast).show();
            return;
        }
        LoadingDialogUtils.show(mContext);
        mPresenter.getData(orderId);
    }

    @OnClick({R.id.tv_kdno_copy, R.id.tv_order_no_copy, R.id.tv_kefu, R.id.tv_look_wuliu, R.id.tv_look_wallet, R.id.tv_ljpj, R.id.tv_invite_friend,
            R.id.tv_sure_sh, R.id.layout_pintuan_userinfo, R.id.cv_shop_info})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {
            return;
        }
        switch (view.getId()) {
            case R.id.tv_kdno_copy:
                //快递单号
                if (pintuanOrderDetailsResponBean != null) {
                    if (TextUtils.isEmpty(pintuanOrderDetailsResponBean.getCourier_no())) {
                        StyleableToast.makeText(mContext, "快递号为空", Toast.LENGTH_SHORT, R.style.mytoast).show();
                        return;
                    }
                    ClipboardUtils.copyText(pintuanOrderDetailsResponBean.getCourier_no(), "复制成功");
                }
                break;

            case R.id.tv_order_no_copy:
                if (pintuanOrderDetailsResponBean != null) {
                    if (TextUtils.isEmpty(pintuanOrderDetailsResponBean.getOrder_no())) {
                        StyleableToast.makeText(mContext, "订单号为空", Toast.LENGTH_SHORT, R.style.mytoast).show();
                        return;
                    }
                    ClipboardUtils.copyText(pintuanOrderDetailsResponBean.getOrder_no(), "复制成功");
                }
                break;
            case R.id.tv_kefu:
                //客服
                new StartActivityUtil(mContext, MyWebviewActivity.class).putExtra("url", Constants.WEBURL_KEFU)
                        .putExtra(Constants.WEBURL_TITLE, Constants.WEBURL_KEFU_TITLE).startActivity(true);
                break;
            case R.id.tv_look_wuliu:
                //查看物流
                if (pintuanOrderDetailsResponBean != null) {
                    if (TextUtils.isEmpty(pintuanOrderDetailsResponBean.getCourier_link())) {
                        StyleableToast.makeText(mContext, "未查询到信息", Toast.LENGTH_SHORT, R.style.mytoast).show();
                        return;
                    }
                    new StartActivityUtil(mContext, MyWebviewActivity.class).putExtra("url", pintuanOrderDetailsResponBean.getCourier_link())
                            .putExtra(Constants.WEBURL_TITLE, Constants.WEBURL_KUAIDI_TITLE).startActivity(true);
                }
                break;
            case R.id.tv_look_wallet:
                //查看钱包
                new StartActivityUtil(mContext, WalletCenterActivity.class).startActivity(true);
                break;
            case R.id.tv_ljpj:
                //立即评价
                if (pintuanOrderDetailsResponBean == null) {
                    StyleableToast.makeText(mContext, "未获取到商品信息,无法进行评价", Toast.LENGTH_SHORT, R.style.mytoast).show();
                    return;
                }
                new StartActivityUtil(mContext, PintuanPjActivity.class)
//                        .putExtra(Constants.PINTUAN_SURE_ORDER_INFO, pintuanOrderDetailsResponBean)
                        .putExtra(Constants.PINTUAN_ID, pintuanOrderDetailsResponBean.getId())
                        .putExtra(Constants.PINTUAN_TITLE, pintuanOrderDetailsResponBean.getGoods_name())
                        .putExtra(Constants.PINTUAN_IMAGE, pintuanOrderDetailsResponBean.getImage())
                        .startActivity(true);
                break;
            case R.id.tv_invite_friend:
                //邀请好友
//                if (pintuanOrderDetailsResponBean == null) {
//                    StyleableToast.makeText(mContext, "未获取到商品信息,无法邀请好友", Toast.LENGTH_SHORT, R.style.mytoast).show();
//                    return;
//                }
//                LoadingDialogUtils.show(mContext);
//                mPresenter.getPtiptGoodsShare(pintuanOrderDetailsResponBean.getGoods_id() + "", pintuanOrderDetailsResponBean.getGroup_id() + "");

                if (pintuanOrderDetailsResponBean == null) {
                    StyleableToast.makeText(mContext, "未获取到信息,无法查看", Toast.LENGTH_SHORT, R.style.mytoast).show();
                    return;
                }
                new StartActivityUtil(mContext, PintuanDetailsActivity.class)
                        .putExtra(Constants.PINTUAN_GROUP_ID, pintuanOrderDetailsResponBean.getGroup_id() + "")
                        .startActivity(true);
                break;

            case R.id.tv_sure_sh:
                //确认收货
                toSureSh();
                break;

            case R.id.layout_pintuan_userinfo:
                //拼团中的用户信息  拼团详情
                if (Constants.PINTUANORDER_FROM_HEAD_LIST == from) {
                    //如果是来自拼团用户头像列表
                    onBackPressedSupport();
                    return;
                }
                if (pintuanOrderDetailsResponBean == null) {
                    StyleableToast.makeText(mContext, "未获取到信息,无法查看", Toast.LENGTH_SHORT, R.style.mytoast).show();
                    return;
                }
                new StartActivityUtil(mContext, PintuanDetailsActivity.class)
                        .putExtra(Constants.PINTUAN_GROUP_ID, pintuanOrderDetailsResponBean.getGroup_id() + "")
                        .startActivity(true);
                break;
            case R.id.cv_shop_info:
                //跳转到商品详情
                if (pintuanOrderDetailsResponBean == null) {
                    StyleableToast.makeText(mContext, "信息出错", Toast.LENGTH_SHORT, R.style.mytoast).show();
                    return;
                }
                new StartActivityUtil(mContext, PintuanShopDetailsActivity.class).putExtra(Constants.PINTUAN_SHOP_ID,
                        pintuanOrderDetailsResponBean.getGoods_id())
                        .startActivity(true);
                break;
            default:
                break;
        }
    }

    private CustomBasePopup customBasePopup;

    /**
     * 确认收货
     */
    public void toSureSh() {
        if (customBasePopup == null) {
            customBasePopup = new CustomBasePopup(mContext, "是否确认收货？", "", "",
                    new CustomBasePopup.PopupWindowCallback() {
                        @Override
                        public void sureClickCallback() {
                            //确认收货
                            mPresenter.ptitakeDelivery(orderId);
                        }

                        @Override
                        public void cancelClickCallback() {

                        }
                    });
            customBasePopup.setPopupGravity(Gravity.CENTER);
        }
        customBasePopup.showPopupWindow();
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(mToolbar)
                .statusBarDarkFont(true)
                .init();
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    public void showContent(PintuanOrderDetailsResponBean bean) {
        LoadingDialogUtils.dismissDialog_ios();
        if (bean != null) {
            this.pintuanOrderDetailsResponBean = bean;
            //重置显示
            tvSuccessCountdown.setText("");

            tvMessage.setText("");

            tvOrderName.setText(TextUtils.isEmpty(bean.getName()) ? "" : bean.getName());

            tvOrderNumber.setText(TextUtils.isEmpty(bean.getMobile()) ? "" : bean.getMobile());

            tvAddressDetails.setText(TextUtils.isEmpty(bean.getAddress_detail()) ? "" : "地址：" + bean.getAddress_detail());

            ImageLoader.load(mContext, bean.getImage(), rvShop);

            tvOrderTitle.setText(bean.getGoods_name());

            String mSpecs = "";
            String mAttribute = "";
            if (!(TextUtils.isEmpty(bean.getSpecs_name()) && TextUtils.isEmpty(bean.getSpecs_value()))) {
                mSpecs = bean.getSpecs_name() + ":" + bean.getSpecs_value();
            }

            if (!(TextUtils.isEmpty(bean.getAttribute_name()) && TextUtils.isEmpty(bean.getAttribute_value()))) {
                mAttribute = bean.getAttribute_name() + ":" + bean.getAttribute_value();
            }
            tvOrderGuige.setText(mSpecs + " " + mAttribute);

            tvSpePrice.setText(TextUtils.isEmpty(bean.getPrice()) ? "" : bean.getPrice());
            //商品价格
            tvShopPrice.setText(TextUtils.isEmpty(bean.getPrice()) ? "" : bean.getPrice());
            //实付款
            tvTruePrice.setText(TextUtils.isEmpty(bean.getActual_payment()) ? "" : bean.getActual_payment());
            //运费
            tvYunfei.setText(StringUtil.isMoreThan(bean.getFreight()) ? bean.getFreight() : "免运费");
            //订单号
            tvOrderNo.setText(TextUtils.isEmpty(bean.getOrder_no()) ? "" : bean.getOrder_no());
            //创建时间
            tvCreateTime.setText(TextUtils.isEmpty(bean.getCreate_time()) ? "" : bean.getCreate_time());
            //支付时间
            tvPayTime.setText(TimeUtils.stampToDate(bean.getPay_time()));
            //顶部信息
            tvMessage.setText(TextUtils.isEmpty(bean.getPrompts()) ? "" : bean.getPrompts());
            //支付方式
            tvPayType.setText(TextUtils.isEmpty(bean.getPay_type()) ? "" : bean.getPay_type());

            if (TextUtils.isEmpty(bean.getOrder_remark())) {
                layoutOrderRemarks.setVisibility(View.GONE);
                layoutOrderRemarksLine.setVisibility(View.GONE);
            } else {
                layoutOrderRemarks.setVisibility(View.VISIBLE);
                layoutOrderRemarksLine.setVisibility(View.VISIBLE);
                tvOrderRemarks.setText(bean.getOrder_remark());
            }
            /**
             *判断拼团状态
             */
//            switch (bean.getGroup_status()) {
//                case 1:
//                    //拼团中
//                    ivShopStatus.setImageResource(R.mipmap.pay_success);
//                    tvStatusText.setTextColor(ContextCompat.getColor(mContext, R.color.pay_success));
//                    tvStatusText.setText("支付成功");
//                    tvPintuanStatus.setText("拼团进行中");
//                    break;
//                case 2:
//                    //成功团
//                    tvStatusText.setTextColor(ContextCompat.getColor(mContext, R.color.colorPrimary));
//                    tvPintuanStatus.setText("拼团成功");
//                    if (bean.getWinning_status() == 1) {
//                        tvStatusText.setText("拼中商品");
//                        ivShopStatus.setImageResource(R.mipmap.icon_shop_status);
//                    } else {
//                        tvStatusText.setText("未拼中商品");
//                        ivShopStatus.setImageResource(R.mipmap.no_general);
//                    }
//                    if (!TextUtils.isEmpty(bean.getCourier_no())) {
//                        //快递单号
//                        layoutKd.setVisibility(View.VISIBLE);
//                        tvKdName.setText(TextUtils.isEmpty(bean.getCourier()) ? "暂无" : bean.getCourier());
//                        tvKdNo.setText(TextUtils.isEmpty(bean.getCourier_no()) ? "暂无" : bean.getCourier_no());
//                        tvKdFhtime.setText(TextUtils.isEmpty(bean.getDelivery_time()) ? "暂无" : bean.getDelivery_time());
//                    }
//                    //水滴
//                    if (!TextUtils.isEmpty(bean.getWater_drop())) {
//                        layoutGetWaterNo.setVisibility(View.VISIBLE);
//                        tvGetWaterNo.setText(bean.getWater_drop());
//                    }
//                    //分红豆
//                    if (!TextUtils.isEmpty(bean.getRed_bean())) {
//                        layoutGetFhd.setVisibility(View.VISIBLE);
//                        tvGetFhd.setText(bean.getRed_bean());
//                    }
//                    //收益
//                    if (!TextUtils.isEmpty(bean.getProfit())) {
//                        layoutGetJssy.setVisibility(View.VISIBLE);
//                        tvGetJssy.setText(bean.getProfit());
//                    }
//                    break;
//                case 3:
//                    //失败团
//                    ivShopStatus.setImageResource(R.mipmap.pay_fail);
//                    tvStatusText.setTextColor(ContextCompat.getColor(mContext, R.color.colorPrimary));
//                    tvStatusText.setText("拼团失败");
//                    tvPintuanStatus.setText("拼团失败");
//                    break;
//                default:
//                    break;
//            }
            /**
             * 底部按钮
             */
            tvSureSh.setVisibility(View.GONE);
            tvLookWuliu.setVisibility(View.GONE);
            tvLjpj.setVisibility(View.GONE);
            tvLookWallet.setVisibility(View.GONE);
            tvInviteFriend.setVisibility(View.GONE);
            if (bean.getStatus() == 1) {
                //拼团中
                tvInviteFriend.setVisibility(View.VISIBLE);
                orderOnLine();
                //启动倒计时
                long currenTime = System.currentTimeMillis() / 1000;
                long endTime = bean.getEnd_time();
                if (endTime > currenTime) {
                    tvMessage.setText("后未成团自动取消订单");
                    long seconds = endTime - currenTime;

                    if (countDownTimer != null) {
                        countDownTimer.cancel();
                    }
                    countDownTimer = new CountDownTimer(seconds * 1000, 1000) {
                        public void onTick(long l) {
                            tvSuccessCountdown.setText(StringUtil.getTimeStr(l));
                        }

                        public void onFinish() {
                            //倒计时结束
                            tvSuccessCountdown.setText("");
                            LoadingDialogUtils.show(mContext);
                            mPresenter.getData(orderId);
                            //倒计时结束 刷新商品信息
                            RxBus.getDefault().post(new SendEvent("", Constants.TYPE_GET_SHOP_INFO));
                        }
                    }.start();
                }
            } else if (bean.getStatus() == 101) {
                //拼团成功 -- 待发货
                orderSuccess(bean);
            } else if (bean.getStatus() == 102) {
                //拼团成功 ---  待收货
                orderSuccess(bean);
                tvSureSh.setVisibility(View.VISIBLE);
                tvLookWuliu.setVisibility(View.VISIBLE);
            } else if (bean.getStatus() == 103) {
                //拼团成功 --- 待评价
                orderSuccess(bean);
                tvLjpj.setVisibility(View.VISIBLE);
            } else if (bean.getStatus() == 104) {
                //拼团成功 --- 获得收益
                orderSuccess(bean);
                tvLookWallet.setVisibility(View.VISIBLE);
            } else if (bean.getStatus() == 105) {
                //拼团成功 --- 已完成
                orderSuccess(bean);
            } else if (bean.getStatus() == 201) {
                //拼团失败--- 正在退款
                orderFail();
            } else if (bean.getStatus() == 202) {
                //拼团失败--- 已退款    暂用删除订单按钮
                orderFail();
                tvLookWallet.setVisibility(View.VISIBLE);
            }

        }
    }

    /**
     * 拼团中
     */
    public void orderOnLine() {
        //拼团中
        ivShopStatus.setImageResource(R.mipmap.pay_success);
        tvStatusText.setTextColor(ContextCompat.getColor(mContext, R.color.pay_success));
        tvStatusText.setText("支付成功");
        tvPintuanStatus.setText("拼团进行中");
    }

    /**
     * 拼团成功
     */
    public void orderSuccess(PintuanOrderDetailsResponBean mBean) {
        //成功团
        tvStatusText.setTextColor(ContextCompat.getColor(mContext, R.color.colorPrimary));
        tvPintuanStatus.setText("拼团成功");
        if (!TextUtils.isEmpty(mBean.getCourier_no())) {
            //快递单号
            layoutKd.setVisibility(View.VISIBLE);
            tvKdName.setText(TextUtils.isEmpty(mBean.getCourier()) ? "暂无" : mBean.getCourier());
            tvKdNo.setText(TextUtils.isEmpty(mBean.getCourier_no()) ? "暂无" : mBean.getCourier_no());
            tvKdFhtime.setText(TextUtils.isEmpty(mBean.getDelivery_time()) ? "暂无" : TimeUtils.stampToDate(mBean.getDelivery_time()));
        }
        //水滴
        if (mBean.getWater_drop() > 0) {
            layoutGetWaterNo.setVisibility(View.VISIBLE);
            tvGetWaterNo.setText(mBean.getWater_drop() + "滴");
        }
        //分红豆
        if (mBean.getRed_bean() > 0) {
            layoutGetFhd.setVisibility(View.VISIBLE);
            tvGetFhd.setText(mBean.getRed_bean() + "个");
        }
        //收益
        if (mBean.getProfit() > 0) {
            layoutGetJssy.setVisibility(View.VISIBLE);
            tvGetJssy.setText(mBean.getProfit() + "元");
        }
        if (mBean.getWinning_status() == 1) {
            tvStatusText.setText("拼中商品");
            ivShopStatus.setImageResource(R.mipmap.icon_shop_status);
        } else {
            tvStatusText.setText("未拼中商品");
            ivShopStatus.setImageResource(R.mipmap.no_general);
            layoutGetWaterNo.setVisibility(View.GONE);
            layoutGetFhd.setVisibility(View.GONE);
        }
    }

    /**
     * 拼团失败
     */
    public void orderFail() {
        //失败团
        ivShopStatus.setImageResource(R.mipmap.pay_fail);
        tvStatusText.setTextColor(ContextCompat.getColor(mContext, R.color.colorPrimary));
        tvStatusText.setText("拼团失败");
        tvPintuanStatus.setText("拼团失败");
    }

    @Override
    public void showMoreContent(String list) {

    }

    @Override
    public void ptitakeDelivery() {
        StyleableToast.makeText(mContext, "收货成功", Toast.LENGTH_SHORT, R.style.mytoast).show();
//        LoadingDialogUtils.show(mContext);
        mPresenter.getData(orderId);
    }

    private ShareShopPopup shareShopPopup;

    @Override
    public void showPtiptGoodsShare(ShareResponBean shareResponBean) {

        LoadingDialogUtils.dismissDialog_ios();
        if (shareResponBean == null || TextUtils.isEmpty(shareResponBean.getShare_image())) {
            StyleableToast.makeText(mContext, "获取分享信息失败", Toast.LENGTH_SHORT, R.style.mytoast).show();
            return;
        }
        String shareText = shareResponBean.getShare_text();
        if (shareShopPopup == null) {
            shareShopPopup = new ShareShopPopup(mContext, mContext, shareText, new ShareShopPopup.ItemClickCallback() {
                @Override
                public void saveImage(String url) {
                    if (!TextUtils.isEmpty(url)) {
                        PermissionUtil.requestPermissionForActivity(mContext, new PermissionUtil.IPermissionListener() {
                            @Override
                            public void permissionGranted() {
                                saveNetImageToLoacl(url);
                            }

                            @Override
                            public void permissionDenied() {
                                ToastUtil.show("权限被拒绝,请设置应用权限");
                            }
                        }, "权限被拒绝,请设置应用权限", PermissionUtil.scan_permissions);
                    }
                }
            });

            float fromX = 0;
            float fromY = 1f;
            float toX = 0;
            float toY = 0;
            Animation showAnimation = createTranslateAnimation(fromX, toX, fromY, toY);
            Animation dismissAnimation = createTranslateAnimation(toX, fromX, toY, fromY);
            shareShopPopup.setShowAnimation(showAnimation);
            shareShopPopup.setDismissAnimation(dismissAnimation);
            shareShopPopup.setPopupGravity(Gravity.BOTTOM);
        }
        shareShopPopup.setImgUrl(shareResponBean.getShare_image());
        shareShopPopup.showPopupWindow();

    }

    private LoadImageDataThread mLoadDataThread;

    public void saveNetImageToLoacl(String downloadPath) {
        boolean isHttp = PictureMimeType.isHttp(downloadPath);
        LoadingDialogUtils.show(mContext, "保存中");
        if (isHttp) {
            mLoadDataThread = new LoadImageDataThread(downloadPath, mHandler, mContext);
            mLoadDataThread.start();
        }
    }

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case Constants.SAVE_IMAGE_SUCCESSFUL:
                    try {
                        String path = (String) msg.obj;
                        if (!TextUtils.isEmpty(path)) {
                            if (!SdkVersionUtils.checkedAndroid_Q()) {
                                File file = new File(path);
                                MediaStore.Images.Media.insertImage(mContext.getContentResolver(), file.getAbsolutePath(), file.getName(), null);
                                new PictureMediaScannerConnection(mContext, file.getAbsolutePath(), () -> {
                                });
                            }
                            StyleableToast.makeText(mContext, "图片保存成功", R.style.mytoast).show();
                        }
                        LoadingDialogUtils.dismissDialog_ios();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    break;
                case Constants.SAVE_IMAGE_ERROR:
                    ToastUtils.s(mContext, getString(R.string.picture_save_error));
                    LoadingDialogUtils.dismissDialog_ios();
                    break;
                default:
                    break;
            }
        }
    };

    @Override
    protected int getTitleIntText() {
        return R.string.order_details_title;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
//        LoadingDialogUtils.dismissDialog_ios();
        if (countDownTimer != null) {
            countDownTimer.cancel();
        }
        if (mLoadDataThread != null) {
            mHandler.removeCallbacks(mLoadDataThread);
            mLoadDataThread = null;
        }
    }
}
